package com.vencent.spring.config;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.util.MultiValueMap;

public class CustomProfileService implements Condition{

	@Override
	public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
		Environment env = context.getEnvironment();
		if(env != null){
			MultiValueMap<String, Object> map = metadata.getAllAnnotationAttributes(CustomeProfile.class.getName());
			if(map != null){
				String value = env.getProperty("profile");
				for(Object obj : map.get("value")){
					if(value != null && value.equals((String)obj)){
						return true;
					}
				}
				return false;
			}
		}
		return false;
	}

}
